package hn.cch.async.controller;

import hn.cch.async.service.ScheduledService;
import hn.cch.async.task.CustomizeTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping(value = "/scheduled")
@RestController
public class ScheduledController {

    @Autowired
    private ScheduledService scheduledService;

    @PostMapping(value = "/start")
    public ResponseEntity<String> start(@RequestBody CustomizeTask customizeTask){
        scheduledService.start(customizeTask);
        return ResponseEntity.ok("");
    }


    @GetMapping(value = "/stop")
    public ResponseEntity<String> stop(@RequestParam(value = "taskName") String taskName){
        scheduledService.stop(taskName);
        return ResponseEntity.ok("");
    }

}
